package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Dao.StudentDao;
import beans.Cou_scores;


/**
 * Servlet implementation class Stu
 */
@WebServlet("/Stu")
public class Stu extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Stu() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
		request.setCharacterEncoding("UTF-8");
		
		String stuID = request.getParameter("stuID");
		StudentDao userAction = new StudentDao();
		//user =new Cou_scores();
		List<Cou_scores>  user =userAction.findByCouID(stuID);
		
		Cou_scores Stu=userAction.findByStuID(stuID);
		
		Cou_scores avar=new Cou_scores();
		String a="false";
		if(Stu!=null){
			
			a="true";
			System.out.println(a);
		float m[]={0,0,0,0,0,0};
		String []n;
		n=new String[6];
    	for(Cou_scores cou:user){
    		//System.out.println(cou.getType());
    	  if(cou.getType().equals("专业技能")){ 
    		
    		  m[0]=m[0]+cou.getScores();
    		  cou.getScores();
    		  /*System.out.println(cou.getScores());*/
    	  }
    	  if(cou.getType().equals("数理水平")){
    		 
    		  m[1]=m[1]+cou.getScores();
    	  }
    	  if(cou.getType().equals("动手实践")){ 
    		 
    		  m[2]=m[2]+cou.getScores();
    	  }
    	  if(cou.getType().equals("外语水平")){ 
    		  m[3]=m[3]+cou.getScores();
    	  }
    	  if(cou.getType().equals("文化素养")){ 
    		  m[4]=m[4]+cou.getScores();
    	  }
    	  if(cou.getType().equals("身体素质")){ 
    		  m[5]=m[5]+cou.getScores();
    	  }
    	  
    	}
    	for(int i=0;i<6;i++){
    		m[i]=m[i]/3;
    		if(m[i]>=90)
    			n[i]="5级";
    		else if(m[i]>=80)
    			n[i]="4级";
    		else if(m[i]>=70)
    			n[i]="3级";
    		else if(m[i]>=60)
    			n[i]="2级";
    		else
    			n[i]="1级";
    	}
    	avar.setStuID(Stu.getStuID());
    	
    	avar.setStuName(Stu.getStuName());
    	
    	avar.setAvar(m);
    	 avar.setGrade(n); 
    	/* for(Cou_scores cou:user){
    		 avar.setStuName(cou.getStuID());
    		 System.out.println(cou.getStuID());
    	 }
    	 /*for(int i=0;i<6;i++){
    	 System.out.println(avar.getAvar()[i]);
    	System.out.println( avar.getGrade()[i]);
    	 }*/
    	request.setAttribute("stuList", user);
    	request.setAttribute("avarge", avar);
    	request.getRequestDispatcher("雷达1.jsp").forward(request, response);
		}else{
			System.out.println(a);
			request.getRequestDispatcher("雷达1.jsp").forward(request, response);
		}
	}
	}


